package com.wenwan.manage.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wenwan.manage.mapper.ArticleCommentClientMapper;
import com.wenwan.manage.service.ArticleCommentClientService;
import com.wenwan.manage.setting.RegExpSetting;
import com.wenwan.manage.setting.StatusSetting;
import com.wenwan.manage.util.Util;

@Service
public class ArticleCommentClientServiceImpl implements ArticleCommentClientService {

	@Autowired
	private ArticleCommentClientMapper articleCommentClientMapper;

	@Override
	public Map<String, Object> create(String content, String fromUserId, String toUserId, String articleCommentId) {
		// TODO Auto-generated method stub
		Map<String, Object> dto = new HashMap<String, Object>();

		if (content != null && content.length() < 20) {
			dto.put("data", false);
			dto.put("msg", "content" + StatusSetting.MSG_10050_LENGTH_IS_CAN_NOT_LESS_FIFTEEN_WORD);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("content" +
			// StatusSetting.MSG_10050_LENGTH_IS_CAN_NOT_LESS_FIFTEEN_WORD);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		if (fromUserId != null && !fromUserId.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "fromUserId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("fromUserId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		if (toUserId != null && !toUserId.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "toUserId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("toUserId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		if (articleCommentId != null && !articleCommentId.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "articleCommentId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("articleCommentId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", Util.UUID());
		map.put("createTime", Util.getTime());
		map.put("updateTime", Util.getTime());
		map.put("content", content);
		map.put("fromUserId", fromUserId);
		map.put("toUserId", toUserId);
		map.put("articleCommentId", articleCommentId);

		Boolean data = articleCommentClientMapper.create(map);
		dto.put("data", data);
		dto.put("msg", StatusSetting.MSG_200);
		dto.put("code", StatusSetting.CODE_200);
		return dto;
	}

	@Override
	public Map<String, Object> deleteById(String id) {
		// TODO Auto-generated method stub
		Map<String, Object> dto = new HashMap<String, Object>();

		if (id != null && !id.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "id" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("id" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);

		Boolean data = articleCommentClientMapper.deleteById(map);
		dto.put("data", data);
		dto.put("msg", StatusSetting.MSG_200);
		dto.put("code", StatusSetting.CODE_200);
		return dto;
	}

	@Override
	public Map<String, Object> update(String id, String content, String fromUserId, String toUserId,
			String articleCommentId) {
		// TODO Auto-generated method stub
		// DataToObject<Boolean> dto = new DataToObject<Boolean>();
		Map<String, Object> dto = new HashMap<String, Object>();

		if (id != null && !id.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "id" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("id" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		if (content != null && content.length() < 20) {
			dto.put("data", false);
			dto.put("msg", "content" + StatusSetting.MSG_10050_LENGTH_IS_CAN_NOT_LESS_FIFTEEN_WORD);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("content" +
			// StatusSetting.MSG_10050_LENGTH_IS_CAN_NOT_LESS_FIFTEEN_WORD);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		if (fromUserId != null && !fromUserId.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "fromUserId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("fromUserId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		if (toUserId != null && !toUserId.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "toUserId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("toUserId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		if (articleCommentId != null && !articleCommentId.matches(RegExpSetting.PARA_ID)) {
			dto.put("data", false);
			dto.put("msg", "articleCommentId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			dto.put("code", StatusSetting.CODE_10050);
			// dto.setData(false);
			// dto.setMsg("articleCommentId" + StatusSetting.MSG_10050_FORMAT_IS_MISTAKE);
			// dto.setCode(StatusSetting.CODE_10050);
			return dto;
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		map.put("content", content);
		map.put("fromUserId", fromUserId);
		map.put("toUserId", toUserId);
		map.put("articleCommentId", articleCommentId);

		Boolean data = articleCommentClientMapper.update(map);
		dto.put("data", data);
		dto.put("msg", StatusSetting.MSG_200);
		dto.put("code", StatusSetting.CODE_200);
		return dto;
	}

}
